package com.qj.daibei.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * author wml
 * Created on 2021/10/7 21:27
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String uri = request.getRequestURI();
//        System.out.println(uri);
//        if ("/".equals(uri) || uri.indexOf("login") != -1 || uri.indexOf("zhuce") != -1 || uri.indexOf("index") != -1) {
//            return true;
//        }

        HttpSession session = request.getSession(false);
        if (session != null) {
            return true;
        }
        request.setAttribute("info","请先登录");
        request.getRequestDispatcher("/login").forward(request, response);
        return false;
    }
}
